package hero;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import core.FlyingObject;

public class Hero extends FlyingObject {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4502214889264545455L;
	private int life =100;
	private int doubleFire = 0;
	private int wing = 2;
	private ArrayList<WingPlane> wps = new ArrayList<>();
	private int flag;
	public static final int ONE_HERO=1;
	public static final int TWO_HERO=2;
	private boolean hasget=false;
	private int score=90;
	private int ultimateSkill=3;
	private boolean ultimateSkillFlag=false;
	
	private static BufferedImage[] image = new BufferedImage[3];
	static {
		image[0] = readImage("src/images/hero0.png");	
		image[1] = readImage("src/images/hero1.png");
		image[2] = readImage("src/images/hero1.png");
	}	
	public Hero() {
		super();
	}
	public Hero(int flag) {
		winPlaneAction();//生成伴随的撩机
		if(flag==ONE_HERO){	
			this.width=118;
			this.height=95;
			this.x=100;
			this.y=450;
		}else if(flag==TWO_HERO) {
			this.width=103;
			this.height=76;
			this.x=250;
			this.y=450;
		}	
		this.flag=flag;
	}

	@Override
	public void step() {
		
	}
	
	public int getScore() {
		return score;
	}	
	public void setScore(int score) {
		this.score = score;
	}
	public void addScore(int score) {
		this.score+=score;
	}
	public void moveTo(int x,int y) {
		this.x=x;
		this.y=y;
		winplaneMove();
	}
	private int heroImageIndex = 0;
	public void paintImage(Graphics g) {
		for(WingPlane w : wps) {
			w.paintImage(g);
		}
		if(flag==ONE_HERO) {			
			g.drawString("生命值="+getLife(), 20, 20);
			g.drawString("得分="+getScore(), 20, 40);
			g.drawString("大招数="+getUltimateSkill(), 20, 60);
		}else {
			g.drawString("生命值="+getLife(), 20, 80);
			g.drawString("得分="+getScore(), 20, 100);
			g.drawString("大招数="+getUltimateSkill(), 20, 120);
		}		
		if(status==live) {
			g.drawImage(image[flag-1], x, y,null);
		}		
	}
	
	public void winplaneMove() {
		wps.get(0).move1(this.x-40, this.y);
		wps.get(1).move1(this.x+84+40, this.y);
	}
	
	public void winPlaneAction() {
		int q=this.height/2;
		ArrayList<WingPlane> wp1 = new ArrayList<>();
		if(wing==1) {
			WingPlane wp = new WingPlane(this.x,(this.y+q));
			wp1.add(wp);
		}else if(wing==2){
			WingPlane wp = new WingPlane(this.x,(this.y+q));
			//wp.move1(this.x-40, this.y);
			WingPlane wp2 = new WingPlane((this.x+this.width),(this.y+q));
			wp1.add(wp);
			wp1.add(wp2);
		}
		wps=wp1;
	}
	
	public int getHeroImageIndex() {
		return heroImageIndex;
	}
	public void setHeroImageIndex(int heroImageIndex) {
		this.heroImageIndex = heroImageIndex;
	}
	public int getLife() {
		return life;
	}
	public void setLife(int life) {
		this.life = life;
	}
	public void addLife() {
		life++;
	}
	public void subtractLife() {
		life--;
		if(life==0) {
			this.status=this.remove;
			for(WingPlane wp:wps) {
				wp.isRemove();
			}
		}
	}
	
	public void setUltimateSkill(int ultimateSkill) {
		this.ultimateSkill = ultimateSkill;
	}
	public boolean isUltimateSkillFlag() {
		return ultimateSkillFlag;
	}
	public void setUltimateSkillFlag(boolean ultimateSkillFlag) {
		this.ultimateSkillFlag = ultimateSkillFlag;
	}
	//获得英雄机的大招数量
	public int getUltimateSkill() {
		return ultimateSkill;//返回英雄机的生命值
	}
	//英雄机减大招数量
	public void subUltimateSkill() {
		ultimateSkill--;
	}
	public int getDoubleFire() {
		return doubleFire;
	}
	public void setDoubleFire(int doubleFire) {
		this.doubleFire=doubleFire;
	}
	public int getHeroWidth() {
		return width;
	}
	
	public void subtractFire() {
		doubleFire -=2;
	}

	public void addDoubleFire(int doubleFire) {
		this.doubleFire += doubleFire;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}	
	public boolean isHasget() {
		return hasget;
	}
	public void setHasget(boolean hasget) {
		this.hasget = hasget;
	}	
	@Override
	public String toString() {
		return "Hero [wps=" + wps + "]";
	}
	public ArrayList<WingPlane> getWps() {
		return wps;
	}
	public void setWps(ArrayList<WingPlane> wps) {
		this.wps = wps;
	}
	
	
}
